#ifndef _HASH_TABLE_H_
#define _HASH_TABLE_H_

#include "libutil.h"

#ifdef __cplusplus
extern "C" {
#endif /** cplusplus **/

typedef struct
{
    int buckets;        /* size of array */
    int items;          /* number of items in hash table */
    int size;           /* table size in bytes */
    value_t **array;    /* array of value_t's */
} htable_t;

#if !defined (get16bits)
#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
                       +(uint32_t)(((const uint8_t *)(d))[0]) )
#endif

#define TIMES 4
/* Create a new hash table */
htable_t *new_htable (int size);
/* Delete a new hash table */
void destroy_htable (htable_t *htable);
/* Find by term */
value_t *htable_find_term (htable_t *htable, char *buf);
/* Find by term id */
value_t *htable_find_id (htable_t *htable, unsigned int buf);
/* Add by term */
void htable_add_term (htable_t *htable, value_t *buf);
/* Add by term id */
void htable_add_id (htable_t *htable, value_t *buf);
/* Remap term id assignments based on frequency */
value_t **remap_freq_htable (htable_t *htable);
/* Write table to stdout for debugging purposes */
void dump_htable (htable_t *htable);
/* Resize a term hash table based on the number of items */
void htable_rehash_id(htable_t*);
/* Resize a term id hash table based on the number of items */
void htable_rehash_term(htable_t*);
/* A robust string hash function */
size_t hash_str ( char *buf, size_t max );
/* A robust integer hash function */
size_t hash_uint ( unsigned int buf, size_t max );

#ifdef __cplusplus
}
#endif /** cplusplus **/

#endif /* _HASH_TABLE_H_ */

